﻿using Pay.Core;
using Pay.DTO;
using Pay.IService;
using Pay.TO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pay.Web.Areas.Admin.Controllers {
    [RouteArea("admin")]
    [RoutePrefix("inviteHorsePowerSetting")]
    public class InviteHorsePowerSettingController : AdminController {
        private IInviteHorsePowerSettingService _iInviteHorsePowerSettingService;

        public InviteHorsePowerSettingController(IInviteHorsePowerSettingService iInviteHorsePowerSettingService) {
            _iInviteHorsePowerSettingService = iInviteHorsePowerSettingService;
        }

        public ActionResult Index() {
            return View();
        }

        public JsonResult Gets(InviteHorsePowerSettingQuery query) {
            var model = _iInviteHorsePowerSettingService.GetInviteHorsePowerSettings(query);
            return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
        }

        public JsonResult Get(long id) {
            invite_horse_power_setting_dto_ex model = new invite_horse_power_setting_dto_ex() {
                status = EInviteHorsePowerSettingStatus.Normal,
                begin_time = DateTime.Now.AddMinutes(10),
                end_time = DateTime.Now.AddMinutes(10).AddDays(1)
            };
            if (id > 0)
                _iInviteHorsePowerSettingService.GetInviteHorsePowerSetting(id).ToCopyProperty(model);
            model.status_value = ((int)model.status).ToString();//ng-select 需要绑定字符串类型
            return Json(ResultToJson.Json(model), JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        [ValidateInput(false)]
        public JsonResult Add(invite_horse_power_setting_dto_ex dto) {
            dto.status = (EInviteHorsePowerSettingStatus)int.Parse(dto.status_value);
            var file_url = Upload("advertisement");
            var result = _iInviteHorsePowerSettingService.AddInviteHorsePowerSetting(dto);
            return Json(ResultToJson.Json(result > 0 ? " 保存成功" : "保存失败", result), JsonRequestBehavior.AllowGet);

        }

        [HttpPost]
        [ValidateInput(false)]
        public JsonResult Update(invite_horse_power_setting_dto_ex dto) {
            dto.status = (EInviteHorsePowerSettingStatus)int.Parse(dto.status_value);
            var result = _iInviteHorsePowerSettingService.UpdateInviteHorsePowerSetting(dto);
            return Json(ResultToJson.Json(result > 0 ? " 保存成功" : "未做任何修改", result), JsonRequestBehavior.AllowGet);

        }

        [HttpPost]
        public JsonResult UpdateStatus(long id, int status) {
            var result = _iInviteHorsePowerSettingService.UpdateInviteHorsePowerSettingStatus(id, status);
            return Json(ResultToJson.Json(result > 0 ? " 修改成功" : "修改失败", result));
        }

    }
}